#include<iostream> 
using namespace std;

struct ListNode {
    int val;
    ListNode *next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
};
class Solution {
public:
    ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) {
        ListNode* ans = new ListNode();
        ListNode* mov = ans;
        while(list1 || list2){
            if(!list1){
                mov->next = list2;
                list2 = list2->next;
            } else if(!list2){
                mov->next = list1;
                list1 = list1->next;
            } else {
                if(list1->val <= list2->val){
                    mov->next = list1;
                    list1 = list1->next;
                } else {
                    mov->next = list2;
                    list2 = list2->next;
                }
            }
            mov = mov->next;
        }
        mov = ans->next;
        delete ans;
        return mov;
    }
};

int main(){
	return 0;
}

/**
 * @brief 2022.4.27重写
 * 
 */